package com.pj.point.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.pj.point.Login;
import com.pj.point.R;
import com.pj.point.self.AboutUs;
import com.pj.point.self.ChangePassword;
import com.pj.point.self.MyMessage;


public class MyFragment extends Fragment {

    Activity activity;
    private ImageView myFragmentImg;
    private ListView myList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        myFragmentImg = (ImageView) view.findViewById(R.id.my_fragment_img);
        myList = (ListView) view.findViewById(R.id.my_list);
        String[] data = {"个人信息","修改密码","关于我们","退出登录"};
        myList.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, data));

        myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (i){
                    case 0 : {
                       startActivity(new Intent(activity, MyMessage.class));
                       break;
                    }
                    case 1 : {
                        startActivity(new Intent(activity, ChangePassword.class));
                        break;
                    }
                    case 2:{
                        startActivity(new Intent(activity, AboutUs.class));
                        break;
                    }
                    case 3:{
                        SharedPreferences.Editor edit = activity.getSharedPreferences("data", Context.MODE_PRIVATE).edit();
                        edit.clear();
                        edit.apply();
                        activity.finish();
                        break;
                    }
                }
            }
        });
    }
}